﻿using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Simpliciti.FunctionalCSharp.Currying;

namespace Simpliciti.FunctionalCSharp.Tests
{
    [TestFixture]
    public class CurryingFixtures
    {
        [Test]
        public void Test_multiplication()
        {
            // Currying
            // F#
            // let multiply x y = x * y
            // let multiplyByThree = multiply 3
            // let multiplyResult = multiplyByThree 15
            Func<int, int, int> multiply = (x, y) => x*y;

            Func<int, Func<int, int>> curriedMultiply = multiply.Curry();
            Func<int, int> curriedMultiplyThree = curriedMultiply(3);
            int curriedMultiplyResult = curriedMultiplyThree(15);

            Assert.That(45, Is.EqualTo(curriedMultiplyResult));
            Console.WriteLine("Result of 3 * 15 = {0}", curriedMultiplyResult);
        }

        [Test]
        public void Test_currying_action()
        {
            // Currying action
            // F#
            // let contains l i = printfn "Item %i is contained: %b" item (l |> List.exists(fun x -> x = i))
            // let containsRange = contains [1..10]
            // let containsResult = containsRange 3
            Action<IEnumerable<int>, int> contains = (items, item) => Console.WriteLine("Item {0} is contained: {1}", item, items.Contains(item));

            var curriedContains = contains.Curry();
            var curriedContainsRange = curriedContains(Enumerable.Range(1, 10));
            curriedContainsRange(5);
        }
    }
}